package log

import (
	"fmt"
	"gopkg.in/natefinch/lumberjack.v2"
	"log/slog"
	"os"
	"path/filepath"
	"sailing.cn/v2/path"
)

func init() {
	logPath := filepath.Join(path.GetExecPath(), "logs", "log.log")
	fmt.Println("日志路径", logPath)
	r := &lumberjack.Logger{
		Filename:   logPath,
		LocalTime:  true,
		MaxSize:    1,
		MaxAge:     3,
		MaxBackups: 5,
		Compress:   true,
	}
	logger := slog.New(slog.NewJSONHandler(r, &slog.HandlerOptions{
		AddSource:   false,
		Level:       nil,
		ReplaceAttr: nil,
	}))
	if os.Getenv("DEBUG") == "" {
		slog.SetDefault(logger)
	}
}
